function static_enemies()

	--Crabby = { name = "crabby", x = 0, y = 0, image = crabby_img,
	--			health = 10, damage = 10, explored = false }

end

function e_move(enemies)


	local absRanX = 0
	local absRanY = 0
	local ranX = 0
	local ranY = 0
	local adjRX = 0
	local adjRY = 0
	local distX = 0
	local distY = 0

	for i = 1, #enemies do
		enemies[i].turn = true
	end



	for i = 1, #enemies do
		--print("inside for loop")
		if enemies[i] ~= nil then
			if enemies[i].x ~= nil and enemies[i].y ~= nil then
				if p_fov(enemies[i].x, enemies[i].y) and enemies[i].turn == true then
					--print("inside pov")

					distX, distY = p_range(enemies[i].x, enemies[i].y)
					--print("distX ", distX, "distY ", distY)

					--if distX > distY then
						if enemies[i].x > data.player.x then
							e_check_move(enemies[i], "left", enemies)
						elseif enemies[i].x < data.player.x then
							e_check_move(enemies[i], "right", enemies)

						end
					--elseif distY > distX then

						if enemies[i].y > data.player.y then
							e_check_move(enemies[i], "up", enemies)
						elseif enemies[i].y < data.player.y then
							e_check_move(enemies[i], "down", enemies)
						end




					--end

				end

				if p_fov(enemies[i].x, enemies[i].y) then
					enemies[i].visible = true
					--print("enemy visible = ", enemies[i].visible)

				else
					enemies[i].visible = false
					--print("enemy visible = ", enemies[i].visible)

				end
			end
		end
	end


	e_finished_turn()

end

function e_show_stats(enemy)


	table.insert(show_enemy, enemy)

end

function e_hide_stats(enemy)

	if show_enemy ~= nil then
		for i = #show_enemy, 1, -1 do
			if enemy.x == show_enemy[i].x and enemy.y == show_enemy[i].y then
				table.remove(show_enemy, i)
			end

		end
	end

end

function e_check_move(enemy, dir, enemies)
	local moved = false

	local priorX = enemy.x
	local priorY = enemy.y
	enemy.priorX = priorX
	enemy.priorY = priorY
	local rX = 0
	local rY = 0

	for i = 1, #enemies do
		if dir == "right" then
			if enemies[i].x == enemy.x+tile_size
				and enemies[i].y == enemy.y then
				enemy.turn = false

			end

		elseif dir == "left" then
			if enemies[i].x == enemy.x-tile_size
				and enemies[i].y == enemy.y then
				enemy.turn = false

			end

		elseif dir == "up" then
			if enemies[i].x == enemy.x
				and enemies[i].y == enemy.y-tile_size then
				enemy.turn = false

			end
		elseif dir == "down" then
			if enemies[i].x == enemy.x
				and enemies[i].y == enemy.y+tile_size then
				enemy.turn = false

			end
		end
	end


	if moved == false then
		for i = 1, #local_map.tiles  do
			if dir == "right" then
				if local_map.tiles[i].x == enemy.x + tile_size
					and local_map.tiles[i].y == enemy.y then
					if local_map.tiles[i].type == "floor"
						and enemy.turn == true then

						enemy.x = enemy.x+tile_size
						moved = true
						enemy.turn = false

					elseif enemy.turn == true then
						rX, rY = p_range_t(enemy.x, enemy.y)
						if rY == 0 then
							e_check_move(enemy, "up", enemies)
						--elseif rY < 0 then
							e_check_move(enemy, "down", enemies)
						end
						moved = true
						enemy.turn = false
					end
				end

			elseif dir == "left" then
				if local_map.tiles[i].x == enemy.x - tile_size
					and local_map.tiles[i].y == enemy.y then
					if local_map.tiles[i].type == "floor"
						and enemy.turn == true then

						enemy.x = enemy.x-tile_size
						moved = true
						enemy.turn = false

					elseif enemy.turn == true then
						rX, rY = p_range_t(enemy.x, enemy.y)
						if rY == 0 then
							e_check_move(enemy, "up", enemies)
						--elseif rY < 0 then
							e_check_move(enemy,"down", enemies)
						end
						moved = true
						enemy.turn = false
					end
				end


			elseif dir == "up" then
				if local_map.tiles[i].x == enemy.x
					and local_map.tiles[i].y == enemy.y - tile_size then
					if local_map.tiles[i].type == "floor"
						and enemy.turn == true then


						enemy.y = enemy.y-tile_size
						moved = true
						enemy.turn = false
					elseif enemy.turn == true then
						rX, rY = p_range_t(enemy.x, enemy.y)
						if rX == 0 then
							e_check_move(enemy, "left", enemies)
							e_check_move(enemy, "right", enemies)
						--elseif rX < 0 then

						end
						moved = true
						enemy.turn = false

					end
				end


			elseif dir == "down" then
				if local_map.tiles[i].x == enemy.x
					and local_map.tiles[i].y == enemy.y + tile_size then
					if local_map.tiles[i].type == "floor"
						and enemy.turn == true then

							enemy.y = enemy.y+tile_size
							moved = true
							enemy.turn = false

					elseif enemy.turn == true then
						rX, rY = p_range_t(enemy.x, enemy.y)
						if rX == 0 then
							e_check_move(enemy, "left", enemies)
						--elseif rX < 0 then
							e_check_move(enemy, "right", enemies)
						end
						moved = true
						enemy.turn = false


					end
				end


			end
		end
	end


end

function e_finished_turn()
	e_damage_player(local_map.enemies)
	data.player.turn = true

end

function e_cleanup(enemies)
	if enemies ~= nil then
		for i = #enemies, 1, -1 do
			if enemies[i].health <= 0 then
				e_loot_spawn(enemies[i])
				data.player.xp = data.player.xp + enemies[i].xp
				e_spawn_corpse(enemies[i].x, enemies[i].y)
				table.remove(enemies, i)

				for j = #show_enemy, 1, -1 do
					if show_enemy[j].id ~= nil then
						if enemies[i] ~= nil then
							if enemies[i].id ~= nil then

								if show_enemy[j].id == enemies[i].id then

									table.remove(show_enemy, j)

								end
							end

						end
					end

				end
			end
		end
	end

end

function e_loot_spawn(enemy)


	local r = RNG:random(1000)

	if r > 750 then

		if r > 875 then
			spawn_seed_bag(enemy.x, enemy.y)
		else
			veggie_generator(enemy.x, enemy.y)
		end

	elseif r < 756 and r > 250 then

		spawn_ammo(enemy.x, enemy.y)

	elseif r < 256 and r > 200 then
		print("spawn hatchet")
		spawn_hatchet(enemy.x, enemy.y)

	end


end

function e_spawn_corpse(x, y)

	Corpse = { x = x, y = y, explored = false, image = blood_splat_img }

	table.insert(local_map.corpses, Corpse)


end

function draw_corpses()

	if local_map.corpses ~= nil then
		for i = 1, #local_map.corpses do

			draw_in_fov(local_map.corpses[i])

		end
	end

end


function enemy_hud()

	if local_map.enemies ~= nil then

		for i = 1, #local_map.enemies do


			if local_map.enemies[i].visible == true
				and local_map.enemies[i].seen == false then

				print("insert : ", local_map.enemies[i].name,
					local_map.enemies[i].id)

				local_map.enemies[i].seen = true

				table.insert(show_enemy, local_map.enemies[i])

			elseif local_map.enemies[i].visible == false then

				if show_enemy ~= nil then

					for j = #show_enemy, 1, -1 do

						if show_enemy[j].id == local_map.enemies[i].id then
							print("remove : ", local_map.enemies[i].name,
								local_map.enemies[i].id)
							table.remove(show_enemy, j)

						end



					end


				end

			end

			for j = #show_enemy, 1, -1 do

				if show_enemy[j].health <= 0 then

					table.remove(show_enemy, j)
				end
			end




		end

		--print(table.tostring(show_enemy))

	end

end

function e_damage_player(enemies)

	for i = 1, #enemies do

		if enemies[i].x == data.player.x and enemies[i].y == data.player.y then
			data.player.health = data.player.health - enemies[i].damage
			enemies[i].y = enemies[i].priorY
			enemies[i].x = enemies[i].priorX

		end
	end

end


function spawn_enemies(enemies, tiles)

	local s_c = 0
	local diffMod = data.player.current_harvest*4



	for i = 1, #tiles do
		if tiles[i].type == "floor" then
			s_c = RNG:random(10000)
			--print(tiles[i].x, tiles[i].y, s_c)

			if s_c > 9500 then
				Crabby = { name = "mite", x = tiles[i].x, y = tiles[i].y,
					image = crabby_img, health = RNG:random(10)+diffMod,
					damage = RNG:random(7)+data.player.current_harvest,
					xp = 0, visible = false, id = 0, seen = false,
					explored = false, turn = false }
				enemy_counter = enemy_counter + 1
				Crabby.xp = Crabby.health+Crabby.damage+diffMod
				Crabby.id = enemy_counter
				--spawn_enemy(Crabby, enemies, tiles[i].x, tiles[i].y)
				table.insert(enemies, Crabby)
			elseif s_c > 9475 and s_c < 9501 then
				Reaper = { name = "reaper", x = tiles[i].x, y = tiles[i].y,
					image = reaper_img, health = RNG:random(15, 30)+diffMod,
					damage = RNG:random(10,20)+data.player.current_harvest,
					xp = 0, visible = false, id = 0, seen = false,
					explored = false, turn = false }
				enemy_counter = enemy_counter + 1
				Reaper.xp = Reaper.health+Reaper.damage+diffMod
				Reaper.id = enemy_counter
				table.insert(enemies, Reaper)
			elseif s_c > 9000 and s_c < 9476 then
				GrassSpider = { name = "grass spider", x = tiles[i].x,
					y = tiles[i].y, image = grass_spider_img,
					health = RNG:random(15)+diffMod,
					damage = RNG:random(4, 12)+data.player.current_harvest,
					xp = 0, visible = false, id = 0, seen = false,
					explored = false, turn = false }
				enemy_counter = enemy_counter + 1
				GrassSpider.xp = GrassSpider.health+GrassSpider.damage+diffMod
				GrassSpider.id = enemy_counter

				table.insert(enemies, GrassSpider)

			end
		end


	end

end



function spawn_enemy(enemies, enemy)

	table.insert(enemies, enemy)

end

function draw_enemies(enemies)

	for i = 1, #enemies do

		if enemies[i] ~= nil then
			if enemies[i].x ~= nil and enemies[i].y ~= nil then
				if p_fov(enemies[i].x, enemies[i].y) then
					draw_in_fov(enemies[i])
				end
			end
		end
	end

end

function spawn_enemy(enemy, enemies, x, y)
	--print(x,y)
	enemy.x = x
	enemy.y = y
	print(enemy.x, enemy.y)

	table.insert(enemies, enemy)

end
